<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.text.*" %>

<!DOCTYPE html>
<html xmlns:c="http://java.sun.com/jsp/jstl/core">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>IntelliFridge_Startseite</title>
<link href="../CSS/main.css" rel="stylesheet" type="text/css">
<link href="../CSS/menu.css" rel="stylesheet" type="text/css">
<link rel="stylesheet"
	href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />

<script type="text/javascript" src="../JS/jquery.js"></script>
<script type="text/javascript"
	src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" src="../JS/UI.js"></script>
<script type="text/javascript" src="../JS/errorhandler_startseite.js"></script>
<script type="text/javascript" src="../JS/deletelm.js"></script>

<c:if test="${empty sessionScope.id}">
	<c:redirect url="../index.jsp?error=3" />
</c:if>

<!-- Plugin für das Pop-Up -->

<script>
	$(function() {
		$("#dialog-message").dialog({
			modal : true,
			buttons : {
				Ok : function() {
					$(this).dialog("close");
				}
			}
		});
	});
</script>

<!-- Include der sql-connect daten -->

<jsp:include page="sql_connect.jsp"></jsp:include>

<!-- Ausgeführte SQL-Querys für die angezeigten tabellen-->

	<sql:query dataSource="${exampleDS}"
	var="javax_servlet_jsp_jstl_sql_Result3" maxRows="30" startRow="0"
	sql="SELECT `Name`, `Menge`, `MHD` FROM `lebensmittelliste` WHERE UserID = ${sessionScope.id} AND MHD BETWEEN 'DATE(now)' AND '2014-02-06' ORDER BY `MHD` asc ">
</sql:query>

<sql:query dataSource="${exampleDS}"
	var="javax_servlet_jsp_jstl_sql_Result" maxRows="30" startRow="0"
	sql="SELECT `ID`,`Name`, `Menge`, `Einheit`, `MHD`, `Marke` FROM `lebensmittelliste` WHERE UserID = ${sessionScope.id} ORDER BY `MHD` asc ">
</sql:query>

<sql:query dataSource="${exampleDS}"
	var="javax_servlet_jsp_jstl_sql_Result2" maxRows="30" startRow="0"
	sql="SELECT `Name`,`Menge`,`Mindestbestand` FROM `lebensmittelliste` WHERE UserID = ${sessionScope.id} AND Menge < Mindestbestand ORDER BY `NAME` asc  ">
</sql:query>

<!-- wenn sich lebensmittel in der übersicht befinden, die innerhalb der nächsten 2 tage ablaufen, wird ein pop-up eingeblendet-->

<c:if test="${javax_servlet_jsp_jstl_sql_Result3.rowCount > 0}">

<c:if test="${sessionScope.anzeige == 0}">

<div id="dialog-message" title="Lebensmittel laufen ab">
  <p>
    Es laufen demnächst folgende Lebensmittel ab:
  </p>
  <p>
    <table id="remindertable">
						<tr>
							<c:forEach
								items="${javax_servlet_jsp_jstl_sql_Result3.columnNames}"
								var="column">
								<th>${column}</th>
							</c:forEach>
						</tr>
						<c:forEach items="${javax_servlet_jsp_jstl_sql_Result3.rows}"
							var="currRow">
							<tr>
								<c:forEach
									items="${javax_servlet_jsp_jstl_sql_Result3.columnNames}"
									var="column">
									<td>${currRow[column]}</td>
								</c:forEach>
							</tr>
						</c:forEach>
					</table>
</div>

<c:set var="anzeige" value="1" scope="session"/>

</c:if>

</c:if>

</head>
<body>

	
<div id="aussenwrapper">
		<div id="innenwrapper">

			<!-- HEADER -->
			<div id="header">
				<div id="logo">
					<img src="../Image/Final.png" height="150" />


				</div>
				<div id="menu">
					<div class="inhalt">
						<ul>
							<li id="current"><a href="startseite.jsp">Home</a></li>
							<li><a href="Eingabe/ean_eingabe_ajax.jsp">Eingabe</a></li>
							<li><a href="konto.jsp">Mein Konto</a></li>
						</ul>
					</div>
				</div>
				<jsp:include page="statusbox.jsp"></jsp:include>
			</div>



			<!--  Content-Bereich -->
			<div id="content">
				<h1 style="margin-top: 15px">Willkommen im Interface von
					intelliFridge</h1>
					<div id="infos"></div>
	
	<!--  Linker-Bereich -->
				<div id="left">

					<h1>Reminder</h1>
					
			
<!--  Tabelle für Erinnerung -->
					<table id="remindertable">
						<tr>
							<c:forEach
								items="${javax_servlet_jsp_jstl_sql_Result2.columnNames}"
								var="column">
								<th>${column}</th>
							</c:forEach>
						</tr>
						<c:forEach items="${javax_servlet_jsp_jstl_sql_Result2.rows}"
							var="currRow">
							<tr>
								<c:forEach
									items="${javax_servlet_jsp_jstl_sql_Result2.columnNames}"
									var="column">
									<td>${currRow[column]}</td>
								</c:forEach>
							</tr>
						</c:forEach>
					</table>
					<!-- Ende linke Box -->
				</div>


			<!--  Rechte Box -->
				<div id="right">

					<h1>Übersicht</h1>
	
					<div>	
						<!-- Tabelle-Index -->
						<table id="remindertable">
							<tr>
								<th>Index</th>
							</tr>
							<c:forEach begin="1"
								end="${javax_servlet_jsp_jstl_sql_Result.rowCount}" var="status">

								<tr>
									<td>${status}</td>
								</tr>
							</c:forEach>
						</table>
						<!--  Tabelle Übersicht -->
						<table id="tbloverview">
							<tr>
								<c:forEach
									items="${javax_servlet_jsp_jstl_sql_Result.columnNames}"
									var="column">
									<th>${column}</th>
								</c:forEach>
							</tr>
							<c:forEach items="${javax_servlet_jsp_jstl_sql_Result.rows}"
								var="currRow">
								<tr>
									<c:forEach
										items="${javax_servlet_jsp_jstl_sql_Result.columnNames}"
										var="column">
										<td>${currRow[column]}</td>
									</c:forEach>
								</tr>
							</c:forEach>
						</table>

					</div>


					<select id="indexdd" name="indexdropbown">
						<c:forEach begin="1"
							end="${javax_servlet_jsp_jstl_sql_Result.rowCount}" var="status">
							<option value="${status}">${status}</option>
						</c:forEach>
					</select>

					<button id="delete" class="button">Löschen</button>
					<button id="change" class="button">Ändern</button>

				</div>
				<!--Ende #middle-->

				<div style="clear: left;"></div>
					
			</div>
			<!--Ende content-->

			<span style="clear: both;"></span>

		
		<!--Ende innenwrapper-->
</div>
		<jsp:include page="footernavi.jsp"></jsp:include>

		<!--Ende footer-->
</div>
	<!--Ende aussenwrapper-->
</body>
</html>